//
//  BCSessonRequst.m
//  BCProjectB
//
//  Created by lanou3g on 15/12/16.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "BCSessonRequst.h"
#import "Reachability.h"
#import "AFNetworking.h"
static BCSessonRequst *helper=nil;
@implementation BCSessonRequst
+(instancetype)shareBCsesson{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        helper=[[BCSessonRequst alloc]init];
    });
    return helper;
}

-(BOOL)checkNetReturnIsNetingOrNot{
    Reachability *reach=[Reachability reachabilityWithHostName:@"www.baidui.com"];
    if ([reach currentReachabilityStatus]!=ReachableViaWiFi&&[reach currentReachabilityStatus]!=ReachableViaWWAN ) {
        return NO;
    }
    return YES;
}
-(void)NetStatueForNeting{
    Reachability *reach=[Reachability reachabilityWithHostName:@"www.baidu.com"];
    if ([reach currentReachabilityStatus]==ReachableViaWiFi) {
        NSLog(@"当前网络状态是Wifi");
    }else if([reach currentReachabilityStatus]==ReachableViaWWAN){
        NSLog(@"当前网络状态为WWAN");
    }else if ([reach currentReachabilityStatus]==NotReachable){
        NSLog(@"当前没有网络");
    }
    
}



-(void)requstReadListView:(void (^)(id objc ))result with:(NSString *)str with:(NSString *)str1 and:(NSString *)str2{
            AFHTTPSessionManager *manger=[AFHTTPSessionManager manager];
         manger.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"application/x-javascript", nil];
        NSDictionary *parameters=@{@"sort":str,@"start":str1,@"typeid":str2,@"client":@"2",@"C8Rm1F32zofhDC8lwEMHrlDJxQML5MOTcp2tvCjBjcWP22NdPTB9Y6P8":@"auth",@"limit":@"10"};
        [manger POST:@"http://api2.pianke.me/read/columns_detail" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            result(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
 
    
}



-(void)getDataWith:(NSString *)url WhenSucess:(void (^)(id))sucessBlock WhenFiled:(void (^)(NSError *))Err{
    if (!url) {
        return;
    }
                NSURL *URL=[NSURL URLWithString:url];
        NSMutableURLRequest *requst=[NSMutableURLRequest requestWithURL:URL];
        NSURLSessionTask *tast=[[NSURLSession sharedSession]dataTaskWithRequest:requst completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
          
            if (error!=nil&&data==nil) {
                return ;
            }
            if (error||data==nil) {
            }
           id requstData=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
            dispatch_async(dispatch_get_main_queue(), ^{
                sucessBlock(requstData);
            });
        }];
        
        
      [tast resume];
  
}

//-(void)getDataWith:(NSString *)url WhenSucess:(void (^)(id))sucessBlock WhenFiled:(void (^)(NSError *))Err{
//    dispatch_async(dispatch_get_global_queue(0, 0), ^{
//        NSURL *URL=[NSURL URLWithString:url];
//        NSMutableURLRequest *requst=[NSMutableURLRequest requestWithURL:URL];
//        NSURLSessionTask *tast=[[NSURLSession sharedSession]dataTaskWithRequest:requst completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//            Err(error);
//         id resObj =[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingAllowFragments) error:nil];
//            dispatch_async(dispatch_get_main_queue(), ^{
//                sucessBlock(resObj);
//            });
//        }];
//        [tast resume];
//  
//    });
//    
//}


@end
